import 'dart:convert';

import 'package:exams_app/gen_a/A.dart';
import 'package:exams_app/home_module/exams_module/view.dart';
import 'package:exams_app/net/Address.dart';
import 'package:exams_app/net/DioManager.dart';
import 'package:exams_app/net/persisten_storage.dart';
import 'package:exams_app/widget/hexcolor.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'package:exams_app/home_module/exams_module/logic.dart';
class ExamsCompletePage extends StatefulWidget {

  var exam_id;
  var title;

  ExamsCompletePage(this.exam_id,{this.title});

  @override
  _ExamsCompletePageState createState() => _ExamsCompletePageState();
}

class _ExamsCompletePageState extends State<ExamsCompletePage>
    with SingleTickerProviderStateMixin {

  HomeModuleLogic logic = Get.put(HomeModuleLogic());

  @override
  void initState() {
    super.initState();

    // requestDataWithComplete(widget.exam_id);

    logic.requestDataWithCommitExams('${widget.exam_id}');
  }

  /// 交卷 接口
  // void requestDataWithComplete(var exam_id) async {
  //   String result =
  //   await DioUtils(url: await PersistentStorage().getStorage('urlStr'))
  //       .postModel(Address.getattt,
  //       model: 'res.exam', function_name: '_api_one',params: {'exam_id':exam_id});
  //
  //   Map json = jsonDecode(result);
  //
  // }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[200],
      appBar: AppBar(
        centerTitle: true,
        leading: IconButton(
          onPressed: (){

           if(widget.title=='考试结果'){

             Get.off(HomeModulePage());

             // Navigator.of(
             //     context)
             //     .pushAndRemoveUntil(
             //     MaterialPageRoute(
             //         builder:
             //             (context) =>
             //             HomeModulePage()),
             //         (route) =>
             //     route ==
             //         null);
           }else{
             Get.back();
           }
          },
          icon: Icon(Icons.arrow_back_rounded,color: Colors.white,),
        ),
        title: Text('${widget.title}'),
      ),
      body: Container(
        clipBehavior: Clip.antiAlias,
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(8.0),
        ),
        margin: EdgeInsets.only(left: 15, right: 15, top: 15),
        height: 330,
        child: GetBuilder<HomeModuleLogic>(
          builder: (_) {
            return Column(
              children: [
                Container(
                  height: 100,
                  color: Theme.of(context).primaryColor,
                  child: Stack(
                    children: [
                      Container(
                        margin: EdgeInsets.only(left: 10, top: 20),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(
                              '此次考试分数',
                              style: TextStyle(
                                  fontSize: 14, color: HexColor('#D7E6FF')),
                            ),
                            Text(
                              '${logic.apidoneJson['data']  ['scores'].toString()}分',
                              style: TextStyle(
                                  color: Colors.white,
                                  fontSize: 21,
                                  fontWeight: FontWeight.w500),
                            ),
                          ],
                        ),
                      ),
                      Align(
                        alignment: Alignment.topRight,
                        child: Image.asset(A.assets_bookbg),
                      ),
                    ],
                  ),
                ),

                Container(
                  margin: EdgeInsets.only(top: 30,left: 15,right: 0,bottom: 15),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text('状态:${logic.apidoneJson['data']['state']}',style: TextStyle(fontSize: 16,color: HexColor('#666666')),),
                      Container(

                          width: 130,
                          child: Text('是否合格:${logic.apidoneJson['data']['type']}',style: TextStyle(fontSize: 16,color: HexColor('#666666')))),
                    ],
                  )
                ),
                Container(
                  margin: EdgeInsets.only(left: 15,right: 0),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text('错题数:${logic.apidoneJson['data']['error']}',style: TextStyle(fontSize: 16,color: HexColor('#666666')),),
                      Container(

                        child:Text('答对数:${logic.apidoneJson['data']['right']}',style: TextStyle(fontSize: 16,color: HexColor('#666666')),),
                        // color: Colors.red,
                        width: 130,
                      )
                    ],
                  )
                ),
               Expanded(child:  Container(
                 margin: EdgeInsets.only(left: 5, right: 5, top: 15),
                 child: Row(
                   mainAxisAlignment: MainAxisAlignment.spaceAround,
                   children: [
                     RaisedButton(
                       shape: RoundedRectangleBorder(
                         borderRadius: BorderRadius.circular(5),
                         side: BorderSide(
                           width: 1,
                           color: HexColor('#D9D9D9'),
                           style: BorderStyle.solid,
                           // style: BorderStyle.none,
                         ),
                       ),
                       child: Text('返回'),
                       elevation: 0,
                       color: Colors.white,
                       onPressed: () {
                         // _swController.
                         if(widget.title=='考试结果'){

                           Get.off(HomeModulePage());

                           // Navigator.of(
                           //     context)
                           //     .pushAndRemoveUntil(
                           //     MaterialPageRoute(
                           //         builder:
                           //             (context) =>
                           //             HomeModulePage()),
                           //         (route) =>
                           //     route ==
                           //         null);
                         }else{
                           Get.back();
                         }

                       },
                     ),
                     // RaisedButton(
                     //   shape: RoundedRectangleBorder(
                     //     borderRadius: BorderRadius.circular(5),
                     //     side: BorderSide(
                     //       width: 1,
                     //       color: Theme.of(context).primaryColor,
                     //       style: BorderStyle.solid,
                     //       // style: BorderStyle.none,
                     //     ),
                     //   ),
                     //   child: Text('再来一次',style: TextStyle(fontSize: 16,color: Colors.white),),
                     //   elevation:0,
                     //   color: Theme.of(context).primaryColor,
                     //   onPressed: (){
                     //
                     //   },
                     // )
                   ],
                 ),
               )),
              ],
            );
          },
        ),
      ),
    );
  }
}
